<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/4 0004
 * Time: 11:24
 */

namespace app\admin\controller;


use think\Db;

class Banner extends Base
{
    const TABLE_IMAGES = 'images';
    public function index()
    {
        if(request()->isPost()){
            $param = input();
            foreach ($param as $k=>$v)
            {
                $value = is_array($v)?join(',',$v):$v;
                Db::name(self::TABLE_IMAGES)->where('name',$k)->update(['value'=>$value]);
            }
            $this->success('保存成功');
        }
        $data = Db::name('images')->where('enable',1)->order('id asc')->select();
        if($data){
            foreach ($data as &$value)
            {
                if($value['is_multi']){
                    $value['value'] = $value['value']?explode(',',$value['value']):null;
                }
            }
        }
        $this->assign('data',$data);
        return $this->fetch();
    }

}